<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1408838">
<link rel=help href="https://github.com/openui/open-ui/issues/639">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<selectlist id=defaultbutton-defaultlistbox>
  <option>one</option>
  <option>two</option>
</selectlist>

<selectlist id=custombutton-defaultlistbox>
  <button type=selectlist>custom button</button>
  <option>one</option>
  <option>two</option>
</selectlist>

<selectlist id=defaultbutton-customlistbox>
  <listbox>
    <option>one</option>
    <option>two</option>
  </listbox>
</selectlist>

<selectlist id=custombutton-customlistbox>
  <button type=selectlist>custom button</button>
  <listbox>
    <option>one</option>
    <option>two</option>
  </listbox>
</selectlist>

<script>
document.querySelectorAll('selectlist').forEach(selectlist => {
  promise_test(async () => {
    assert_false(selectlist.matches(':open'),
      'The listbox should not be showing at the start of the test.');

    await test_driver.click(selectlist);
    assert_true(selectlist.matches(':open'),
      'The listbox should be showing after clicking the button.');

    await test_driver.click(selectlist);
    assert_false(selectlist.matches(':open'),
      'The listbox should be closed after clicking the button.');
  }, `${selectlist.id}: Clicking the selectlist's button should toggle the listbox.`);
});
</script>
